// pages/choujiang2/choujiang2.js
const app = getApp()
import {timestampToTime} from "../../utils/util.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
apiimg: app.apiimg,
    autoplay: true,
    interval: 2000,
    duration: 500,
    list2:[
      'SKll精华','SKll精华','SKll精华'
    ],
    list:[
      '1','2','3','4','5'
    ],
    tanchu15:false,
    idx:0,
    kaixiang:false,
    kklist:[],
    page_no:1,
    page_no1:1
  },
z_qiehuan1(){
  this.setData({
    idx:0
  })
},
z_qiehuan2(){
  this.setData({
    idx:1
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		let lucksData = [{ //这里修改后，可以通过后台请求配置
			"key": "baofu",
			"name": "暴富",
			"indexli": 1
		}, {
			"key": "facai",
			"name": "1个月工资",
			"indexli": 2
		}, {
			"key": "one",
			"name": "财务自由",
			"indexli": 3
		}, {
			"key": "byebye",
			"name": "谢谢惠顾",
			"parentsClass":"外部引入样式demo",
			"indexli": 8
		}, {
			"key": "start_btn",
			"name": "抽奖",
			"indexli": -1
		}, {
			"key": "byebye",
			"name": "谢谢惠顾",
			"indexli": 4
		}, {
			"key": "bonus",
			"name": "1年奖金",
			"indexli": 7
		}, {
			"key": "car",
			"name": "一辆轿车",
			"indexli": 6
		}, {
			"key": "tendays",
			"name": "10天年假",
			"indexli": 5
		}];
		this.setData({
			lucksData
    })
  },
	luckCb(e){
		console.log(e);
		// if(e.detail){
		// 	this.setData({
		// 		luck_num:e.detail
		// 	})
    // }
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
      "luck_id":e.detail
    }
    wx.request({
      url: app.apiurl + 'api/member/extractLuckBagBs',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
      }
    })
  },
  luckCb1(e){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
      "nums":e.detail
    }
    wx.request({
      url: app.apiurl + 'api/member/extractTreasureBox',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          kklist:res.data.data
        })
      }
    })
  },
  sendMsg1(){
    this.setData({
      kaixiang:true
    })
  },
  z_open(){
    this.setData({
      tanchu15:true
    })
  },
  z_close(){
    this.setData({
      tanchu15:false,
      kaixiang:false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.z_baoxiang1()
    this.z_baoxiang2()
    this.z_yonghu()
    this.z_yonghu1()
    this.z_jiangpin()
    this.z_jilu1()
    // this.z_jilu2()
    this.z_jilu3()
  },
  z_baoxiang1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/boxList',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          lucksData1:res.data.data
        })
      }
    })
  },
  z_baoxiang2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/luck_bag/luckBagList',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          lucksData2:res.data.data
        })
      }
    })
  },
  z_yonghu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
       if(res.data.code == '1001'){
         _this.setData({
           login:true,
           yonghu:res.data.data
         })
       }
      }
    })
  },
  z_yindao(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
      "yd_status":'3'
    }
    wx.request({
      url: app.apiurl + 'api/member/upMyYd',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
      }
    })
  },
  z_yonghu1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/season/seasonCurInfo',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           yonghu1:res.data.data
         })
       }
    })
  },
  z_jiangpin(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/prize/list?page_no=' + _this.data.page_no + '&page_num=10&type=2&con_type=5&origin=0&name=',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           list:res.data.data.list
         })
      }
    })
  },
  z_jilu1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/lotteryRecord?page_no=' + _this.data.page_no1 + '&page_num=10&type=1',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           list1:res.data.data.list
         })
      }
    })
  },
  z_jilu2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/season/seasonPrizeList',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           list2:res.data.data
         })
      }
    })
  },
  z_jilu3(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/season/info',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           newjifen:res.data.data,
           time1:res.data.data.diff_time
         })
         _this.z_time()
      }
    })
  },
  z_time(){
    let _this = this
    let sjc = _this.data.time1
    _this.setData({
      time2:timestampToTime(sjc,3)
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 //下滑刷新
//  let _this = this
//  let page_no  = _this.data.page_no
//  page_no = page_no+1
//  let page_no1  = _this.data.page_no1
//  page_no1 = page_no1+1
//  _this.setData({
//    page_no:page_no,
//    page_no1:page_no1
//  })
//  _this.z_jiangpin()
//  _this.z_jilu1()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})